{include file="common/mainHead"/}
<div class="admin-main fadeInUp animated">
    <blockquote class="layui-elem-quote">
        <a href="{:url('adminAdd')}" class="layui-btn layui-btn-small">
            <i class="fa fa-plus"></i> 商户入驻
        </a>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>{:lang('admin')}{:lang('list')}</legend>
        <div class="layui-field-box table-responsive">
            <table class=" layui-table table-hover">
                <thead>
                <tr>
                    <th>{:lang('username')}</th>
                    <th>{:lang('email')}</th>
                    <th>{:lang('userGroup')}</th>
                    <th>{:lang('tel')}</th>
                    <th>{:lang('ip')}</th>
                    <th>是否推荐</th>
                    <th>{:lang('action')}</th>
                </tr>
                </thead>
                <tbody id="con">
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="7">
                        <!--分页容器-->
                        <div id="paged" style="text-align: right"></div>
                    </td>
                </tr>
                </tfoot>
            </table>

        </div>
    </fieldset>
</div>
<script type="text/html" id="conTemp">
    {{# layui.each(d.list, function(index, item){ }}
    <tr>
        <td>{{ item.username}}</td>
        <td>{{ item.email}}</td>
        <td>{{ item.title}}</td>
        <td>{{ item.tel}}</td>
        <td>{{ item.ip}}</td>
        <td>


            {{# if(item.admin_id==1){ }}

                <div>
                    <button disabled class="layui-btn layui-btn-mini layui-btn-disabled">{:lang('enabled')}</button>
                </div>
            {{# }else{  }}
                {{# if(item.is_open==1){ }}
<span id="s_{{item.admin_id}}">
                <a href="javascript:;"  onclick="return checkStatus({{item.admin_id}},0)"  class="layui-btn layui-btn-mini layui-btn-radius layui-btn-warm">已推荐 </a>
            </span>
                {{# }else{  }}
       <span id="s_{{item.admin_id}}">


                <a href="javascript:;"  onclick="return checkStatus({{item.admin_id}},1)" class="layui-btn layui-btn-mini layui-btn-radius ">未推荐</a>
                        
       </span>
                {{# } }}
            {{# } }}
        </td>
        <td>
            <a href="{:url('adminEdit')}?admin_id={{item.admin_id}}" class="layui-btn layui-btn-mini">{:lang('edit')}</a>
            {{# if(item.admin_id==1){ }}
            <a href="#" class="layui-btn layui-btn-mini layui-btn-disabled">{:lang('del')}</a>
            {{# }else{  }}
            <a href="javascript:;" onclick="return del({{item.admin_id}})" class="layui-btn layui-btn-danger layui-btn-mini">{:lang('del')}</a>
            {{# } }}
        </td>
    </tr>
    {{# }); }}
</script>
{include file="common/mainFoot"/}
<script>
    layui.config({
        base: '__ADMIN__/js/'
    }).use(['paging','form', 'layer'], function() {
        var paging = layui.paging(),form = layui.form(), layer = layui.layer;
        paging.init({
            url: "{:url('adminList')}", //地址
            elem: '#con', //内容容器
            params: {}, //发送到服务端的参数
            tempElem: '#conTemp', //模块容器
            pageConfig: { //分页参数配置
                elem: '#paged', //分页容器
                pageSize: 15 //分页大小
            },
            success: function() { //渲染成功的回调
                //alert('渲染成功');
            },
            fail: function(msg) { //获取数据失败的回调
                //alert('获取数据失败')
            },
            complate: function() { //完成的回调
                //alert('处理完成');
            }
        });
        //搜索
        $('#search').on('click', function() {
            var $this = $(this);
            var key = $('#key').val();
            if($.trim(key)=='') {
                layer.msg('{:lang('pleaseEnter')}关键字！');
                return;
            }
            //调用get方法获取数据
            paging.get({
                key: key //获取输入的关键字。
            });
        });

    });
    //删除事件
    function del(id) {
        if (id == 1) {
            layer.msg('{:lang("Super administrator cannot be deleted")}', {time: 1800,icon:0});
            return false;
        }
        layer.confirm('{:lang("Are you sure you want to delete it")}', {icon: 3}, function (index) {
            window.location.href = "{:url('adminDel')}?admin_id="+id;
        });
    }

//审核状态
    function checkStatus(id,status) {

        //超级管理员状态不能修改
        // if (id == 1) {
        //     layer.msg('系统管理员不能修改状态', {time: 1800,icon:0});
        //     return false;
        // }
        //普通商户(id<>1)
        layer.confirm('确定要推荐该商户吗？', {icon: 3}, function (index) {
    
            var surl="{:url('upAdminStatus')}";
         

            $.post(surl,{admin_id:id,is_open:status},function(result){
               
               
                var smsg=result==1?"操作成功":"操作失败";
                layer.msg(smsg);
                layer.confirm(smsg, {icon: 3}, function (index) {
                    layer.close(index);
                    window.location.href = "{:url('adminList')}";
        });


               
            });
          
    });
    };
    function stateyes(id) {
        $.post('{:url("adminState")}',{'id': id},function (data) {
            if (data.status==1) {
                if (data.info == "{:lang('disabled')}") {
                    var a = '<button class="layui-btn layui-btn-danger layui-btn-mini">{:lang("disabled")}</button>'
                    $('#zt' + id).html(a);
                    return false;
                } else {
                    var b = '<button class="layui-btn layui-btn-warm layui-btn-mini">{:lang("enabled")}</button>'
                    $('#zt' + id).html(b);
                    return false;
                }
            }else{
                layer.msg(data.msg,{time:1000,icon:2});
                return false;
            }
        });
        return false;
    }
</script>